extends CharacterBody2D

## 速度
@export var speed := 200.0
## 追击目标
var target : Array[Node2D] = []


func die() -> void:
	get_node("/root/Startup").point += 1
	queue_free()


func _on_find_area_body_entered(body: Node2D) -> void:
	target.append(body)


func _on_find_area_body_exited(body: Node2D) -> void:
	target.erase(body)



func _physics_process(delta: float) -> void:
	if multiplayer.is_server():
		move(delta)


func move(_delta: float) -> void:
	if target.size():
		velocity = global_position.direction_to(target[target.size() - 1].global_position) * speed
		move_and_slide()
		for c in get_slide_collision_count():
			if get_slide_collision(c).get_collider():
				die()
				break


